package cn.jaye.fabric.application;

import cn.jaye.fabric.application.command.LoginCommand;
import cn.jaye.fabric.common.constant.FabricConstant;
import cn.jaye.fabric.common.constant.Global;
import cn.jaye.fabric.common.constant.MicroConstant;
import cn.jaye.fabric.domain.service.RestTemplateService;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

//import com.eking.session.domain.model.Esession;

/**
 * @author Jaye
 * @create 2017-12-26 14:38
 */
@Service
public class AuthApplicationService {


    @Autowired
    private RestTemplateService restTemplateService;

    @Autowired
    private FabricConstant fabricConstant;

    private static final String GATEWAY_ADDRESS = "gateway-address";
    private static final String USER_REGISTER = "user-register";
    private static final String USER_LOGIN = "user-login";
    public boolean login(LoginCommand loginCommand) {
        if (StringUtils.isNotBlank(loginCommand.getUsername()) && StringUtils.isNotBlank(loginCommand.getPassword())) {
            String url = "http://localhost:8080"+"/user/login";
            JSONObject postData = new JSONObject();
            postData.put("username", loginCommand.getUsername());
            postData.put("password", loginCommand.getPassword());
            postData.put("orgId", loginCommand.getOrgId());
            JSONObject resultObject = restTemplateService.getUrlResponse(url, postData);
            if (Global.SUCCESS_FLAG.equals(resultObject.getInteger("code"))) {
                return true;
            }
        }
        return false;
    }

    public void logout(String sessionId) {
//        esession.setTimeOut(sessionId, 0);
    }

}
